package com.alks.function.controller.stockdept.pcfactorystockquery;


import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.common.utils.excelUtils.ExcelPoiUtils;
import com.alks.common.utils.excelUtils.ExcelUtils;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.stockdept.pcfactorystockwork.*;
import com.alks.function.data.vo.stock.MtlAccVo;
import com.alks.function.service.stockdept.pcfactorystockquery.IPcMtlCheckService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 材料暂收表 前端控制器
 * </p>
 *
 * @author ms
 * @since 2023-08-23
 */
@RestController
@ApiRestController("/pcFactorStockQuery")
@Api(value = "仓储部查询",tags = "仓储部-仓储工厂作业-材料暂收入库")
@Slf4j
@RoleCheck(prgIds = {"160101"})
public class PcMtlCheckController {
    @Autowired
    IPcMtlCheckService disService;

    private final int slipType = 0;

    @PutMapping("/getPurUnSentQuery")
    @ApiOperation(value = "材料暂收入库-订购未收查询-分页可条件查询",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo getPurUnSentQuery(@RequestBody MpPurDisRequest request){
        return disService.getPurUnSentQuery(request,slipType);
    }

    @PutMapping("/getPurSentQuery")
    @ApiOperation(value = "材料暂收入库-订购已收查询-分页可条件查询",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo getPurSentQuery(@RequestBody MpPurDisRequest request){
        return disService.getPurSentQuery(request,slipType);
    }

    @PutMapping("/sentMtlTypeQuery")
    @ApiOperation(value = "材料暂收入库-分类定义-查询",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo sentMtlTypeQuery(){
        return disService.sentMtlTypeQuery();
    }

    @PutMapping("/purSentAdd")
    @ApiOperation(value = "材料暂收入库-暂收入库-新增",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purSentAdd(@RequestBody List<AddPurSendRequest> request,
                                   @RequestParam(required = false)@ApiParam(value = "公司名称") String vendorNo,
                                   @RequestParam(required = false)@ApiParam(value = "送货单号"  ) String sendNo){
        return disService.purSentAdd(request,vendorNo,sendNo,slipType);
    }

    @PutMapping("/sentMtlTypeAdd")
    @ApiOperation(value = "材料暂收入库-分类定义-增删",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo sentMtlTypeAdd(@RequestBody List<UserMtlTypeRequest> requests,
                                       @RequestParam@ApiParam("标志位（1.选择分类 2.还原分类）") Integer flag){
        return disService.sentMtlTypeAdd(requests,flag);
    }

//    @PutMapping("/purStockAdd")
//    @ApiOperation(value = "材料暂收入库-转入仓库-新增",tags = "仓储部-仓储工厂作业-材料暂收入库")
//    public ResponseInfo purStockAdd(@RequestBody List<AddPurSentRequest> request){
//        return disService.purStockAdd(request);
//    }

    @PutMapping("/purPutStockUpdate")
    @ApiOperation(value = "材料暂收入库-入库批处理-修改",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purPutStockUpdate(@RequestBody List<PurSentRequest> request){
        return disService.purPutStockUpdate(request);
    }
//
//    @PutMapping("/purSentRemark")
//    @ApiOperation(value = "材料暂收入库-写入备注-修改",tags = "仓储部-仓储工厂作业-材料暂收入库")
//    public ResponseInfo purSentRemark(@RequestParam String id,
//                                      @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate sendDate,
//                                      @RequestParam String sendNo){
//        return disService.purSentRemark(request);
//    }

    @GetMapping("/purStockUpdate")
    @ApiOperation(value = "材料暂收入库-转入仓库-新增/修改",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purStockUpdate(@RequestParam String recNo){
        return disService.purStockUpdate(recNo);
    }

    @PutMapping("/purSentDelete")
    @ApiOperation(value = "材料暂收入库-修改-删除",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purSentDelete(@RequestBody List<PurSentRequest> request){
        return disService.purSentDelete(request);
    }

    @PutMapping("/purSentRemark")
    @ApiOperation(value = "材料暂收入库-修改-删除",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purSendUpdate(@RequestParam Integer primaryId,
                                      @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate sendDate,
                                      @RequestParam String sendNo,
                                      @RequestParam String remark){
        disService.purSendUpdate(primaryId,sendDate.atStartOfDay(),sendNo,remark);
        return ResponseInfo.ok();
    }

    @GetMapping("/purStockBack")
    @ApiOperation(value = "材料暂收入库-厂商，分类-回显",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo purStockBack(){
        return disService.purStockBack();
    }

    @PutMapping("/mtl/invCount")
    @ApiOperation(value = "仓库盘点",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo mtlInvCount(MultipartFile file){
        /*仓库盘点*/
        List<MtlAccVo> read = ExcelUtils.passRow(2).read(file, MtlAccVo.class);
        disService.mtlInvCount(read);
        return ResponseInfo.ok();
    }

    @PutMapping("/mtl/printMiss")
    @ApiOperation(value = "导出不存在的物料信息",tags = "仓储部-仓储工厂作业-材料暂收入库")
    public ResponseInfo printMiss(MultipartFile file, HttpServletResponse response){
        /*仓库盘点*/
        List<MtlAccVo> read = ExcelUtils.passRow(2).read(file, MtlAccVo.class);
        disService.printMiss(read,response);
        return ResponseInfo.ok();
    }
}
